<?php
/**
 * Created by Bruce.
 * IDE: PhpStorm
 * Date: 2018/8/7
 * Time: 17:51
 */

namespace app\park\controller;


use app\park\model\AdminQueryBillModel;
use think\Request;

class AdminQueryBill
{
	private $openId;

	/**
	 * @param Request $request 查询指定月流水账单统计
	 * @return string  返回（共多少笔交易，共多少收益）
	 */
	public function queryByDate(Request $request)
	{
		$this->openId = $request->post('openId');
		$date = $request->post('date');

		$args = ['openId' => $this->openId, 'date' => $date];
		$result = $this->checkArgs($args);
		if ($result == 'ok') {
			$mode = new AdminQueryBillModel();
			$response = $mode->queryByDate($this->openId, $date);
			return $response;
		} else {
			return ['code' => '300', 'result' => $result];
		}

	}

	public function queryBill(Request $request)
	{
		$this->openId = $request->post('openId');
		$start = $request->post('start');
		$nu = $request->post('nu');
		$result = $this->checkArgs(['openId' => $this->openId, 'start' => $start, 'nu' => $nu]);
		if ($result == 'ok') {
			$mode = new AdminQueryBillModel();
			$res = $mode->queryBill($this->openId, $start, $nu);
			return $res;
		} else {
			return ['code' => '300', 'result' => $result];
		}

	}

	private function checkArgs(array $array)
	{
		$result = '';
		foreach ($array as $key => $value) {
			if ($value=='') {
				$result .= $key . ' is null  ';
			}
		}
		if (empty($result)) {
			return 'ok';
		} else {
			return $result;
		}
	}
}
